package com.xiaocz.hblsubstitutedriving.adapter;

import android.graphics.Paint;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xiaocz.common.widgets.recycler.RecyclerViewAdapter;
import com.xiaocz.hblsubstitutedriving.R;
import com.xiaocz.hblsubstitutedriving.model.Rechargelist;


/**
 * Author:  xiaocz.
 * Date:    2018/05.04.
 * Descr:  会员类型
 */
public class VipTypeAdapter extends RecyclerViewAdapter<Rechargelist> {

    private static onClickListener onClickListener;

    public VipTypeAdapter(AdapterListener<Rechargelist> adapterListener) {
        super(adapterListener);
    }

    public void vipTypeAdapter(onClickListener onClickListener) {
        VipTypeAdapter.onClickListener = onClickListener;
    }

    @Override
    protected int getItemViewType(int position, Rechargelist data) {
        return R.layout.item_vip_type;
    }

    @Override
    protected ViewHolder<Rechargelist> getViewHolder(View view, int viewType) {
        return new InfoTypeViewHolder(view);
    }

    private static class InfoTypeViewHolder extends ViewHolder<Rechargelist> {

        private LinearLayout layoutBase;
        private TextView tvTitle, tvMoney, one_info;

        InfoTypeViewHolder(View itemView) {
            super(itemView);
            layoutBase = itemView.findViewById(R.id.layout_base);
            tvTitle = itemView.findViewById(R.id.time);
            tvMoney = itemView.findViewById(R.id.one_month_money);
            one_info = itemView.findViewById(R.id.one_info);
        }

        @Override
        protected void onBind(final Rechargelist data, final int position) {
            tvTitle.setText(String.format(data.getTimecount() + "%s", data.getTimeunit()));
            tvMoney.setText(String.valueOf(data.getCurrentPrice()));
            one_info.setText(String.format("%s元", data.getOriginalPrice()));
            if (data.isState()) {
                layoutBase.setBackground(mContext.getResources().getDrawable(R.drawable.btn_shape_radius_w));
                tvTitle.setTextColor(mContext.getResources().getColor(R.color.colorIndexDark));
            } else {
                layoutBase.setBackground(mContext.getResources().getDrawable(R.drawable.btn_shape_radius_hui));
                tvTitle.setTextColor(mContext.getResources().getColor(R.color.textColorThird));
            }
            one_info.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

//            tvPay.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    onClickListener.onClickButton(1, position, data);
//                }
//            });
        }

        @Override
        public boolean isNeedClick() {
            return true;
        }
    }

    public interface onClickListener {
        void onClickButton(int value, int position, Rechargelist data);
    }
}